<?php
/**
 * Representation of a class property
 */
class My_Code_Class_Property
{
    protected $name;
    protected $visibility = 'public';
    protected $isStatic = false;
    protected $defaultValue;
    protected $type;

    protected function  __construct()
    {
    }

    /**
     * @return My_Code_Class_Property
     */
    public static function factory()
    {
        return new self();
    }

    /**
     * @param string $name
     * @return My_Code_Class_Property
     */
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }

    /**
     * @param string $visibility
     * @return My_Code_Class_Property
     */
    public function setVisibility($visibility)
    {
        $this->visibility = $visibility;
        return $this;
    }

    /**
     * @return My_Code_Class_Property 
     */
    public function staticProperty()
    {
        $this->isStatic = true;
        return $this;
    }

    /**
     * @param mixed $defaultValue
     * @return My_Code_Class_Property
     */
    public function setDefaultValue($defaultValue)
    {
        $this->defaultValue = $defaultValue;
        return $this;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @return string
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * @param string $type
     * @return My_Code_Class_Property
     */
    public function setType($type)
    {
        $this->type = $type;
        return $this;
    }


    /**
     * @return string
     */
    public function toString()
    {

        if (!is_null($this->defaultValue))
        {
            $template = "%s %s = '%s';";
            $code = sprintf($template, $this->visibility, (true == $this->isStatic) ? 'static $'. $this->name : '$'. $this->name, $this->defaultValue);
        }
        else
        {
            $template = "%s %s;";
            $code = sprintf($template, $this->visibility, (true == $this->isStatic) ? 'static $'. $this->name : '$'. $this->name);
        }

        return $code;
    }
    
}